/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gestaoFuneraria.DAO;

import br.com.gestaoFuneraria.modelo.Loculo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class LoculoDAO {

    private Connection conexao;

    public void cadastrar(Loculo l) throws SQLException {
        String sql = "  INSERT INTO loculo(ds_condicao_loculo,cd_associado,nm_rua)Values(?,?,?)";
        PreparedStatement stmt = conexao.prepareStatement(sql);
        //stmt.setInt(1, l.getId());
        stmt.setString(1, l.getDescricao());
        stmt.setInt(2, l.getIdAssociado());
        stmt.setString(3, l.getRua());
        stmt.execute();
        stmt.close();
    }

    public List<Loculo> getLista() throws SQLException {
        String sql = "SELECT * FROM loculo";
        PreparedStatement stmt = this.conexao.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();

        List<Loculo> loculos = new ArrayList<Loculo>();
        while (rs.next()) {
            Loculo l1 = new Loculo();
            l1.setId(Integer.parseInt(rs.getString("cd_loculo")));
            l1.setDescricao(rs.getString("ds_condicao_loculo"));
            l1.setIdAssociado(Integer.parseInt(rs.getString("cd_associado")));
            l1.setRua(rs.getString("nm_rua"));
            loculos.add(l1);
        }
        rs.close();
        stmt.close();
        return loculos;
    }
//     public void altera(Associado a1) throws SQLException {
//        String sql = "UPDATE associado set cd_associado=?, nm_associado=?, cd_registro_geral_associado=?, cd_cpf_associado=?,cd_titutlo_eleitoral_associado=?,ic_sexo_masculino_feminino=?,nm_filiacao=?,dt_nascimento_associado=?,nm_endereco_associado=?,nm_cidade_associado=?,sg_unidade_federativa_associado=?,cd_cep_associado=?,cd_funcionario=? where cd_associado=?";
//        PreparedStatement stmt = conexao.prepareStatement(sql);
//        stmt.setInt(1, a1.getId());
//        stmt.setString(2, a1.getNome());
//        stmt.setString(3, a1.getRg());
//        stmt.setString(4, a1.getCpf());
//        stmt.setString(5, a1.getTituloEleitoral());
//        stmt.setString(6, a1.getSexo());
//        stmt.setString(7, a1.getFiliacao());
//        stmt.setString(8, a1.getDataNascimento());
//        stmt.setString(9, a1.getEndereco());
//        stmt.setString(10, a1.getCidade());
//        stmt.setString(11, a1.getUf());
//        stmt.setString(12, a1.getCep());
//        stmt.setInt(13, a1.getIdFuncionario());
//        //executa o PreparedStatement
//        stmt.execute();
//        stmt.close();

    public LoculoDAO() throws SQLException {
        this.conexao = Conexao.getConexao();
    }
}
